home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / program / ny_src.zip / CHATADD.CPP < prev    next >
C/C++ Source or Header  |  1997-04-22  |  12KB  |  306 lines

  1. #include "ny2008.h"
  2.  
  3. //void ny_clr_scr(void);
  4. void chat_new_line(void);
  5. extern int rip;
  6. extern unsigned _stklen;
  7.                     /* FULL-SCREEN CHAT CUSTOMIZATION OPTIONS */
  8.  
  9. char window_colour[2]={0x0b,0x0c};        /* Text colour used for each person */
  10. char bar_colour=0x70;                      /* Colour of window seperation bar */
  11. char top_line[2]={1,13};       /* Specifies location of each window on screen */
  12. char bottom_line[2]={11,23};          /* Line number of bottom of each window */
  13. char bar_line=12;                     /* Line number of window seperation bar */
  14. char scroll_distance=9;            /* Distance to scroll window when required */
  15. char cursor_window;                     /* FULL-SCREEN CHAT INTERNAL VARIABLES */
  16. char current_word[2][81];
  17. int word_length[2];
  18. int cursor_col[2];
  19. int cursor_line[2];
  20. unsigned char key;
  21. int old_chat_key;
  22. int command[2]={FALSE,FALSE}; /*no commands being used*/
  23.  
  24.                          /* FULL-SCREEN CHAT FUNCTION */
  25. void fullscreen_chat(void)
  26.    {
  27.    cursor_window=0;                                /* Reset working variables */
  28.    word_length[0]=word_length[1]=0;
  29.    cursor_col[0]=cursor_col[1]=1;
  30.    cursor_line[0]=top_line[0];
  31.    cursor_line[1]=top_line[1];
  32.  
  33.  
  34.  
  35.  
  36.               /* If ANSI or AVATAR graphics mode is not available */
  37.    if(!od_control.user_ansi && !od_control.user_avatar)
  38.       {
  39.       od_chat();                /* Then use OpenDoor's line chat mode instead */
  40.       return;
  41.       }
  42.  
  43.    old_chat_key=od_control.key_chat;       /* Prevent internal chat mode from */
  44.    od_control.key_chat=0;                                    /* being invoked */
  45.                               /* DRAW THE CHAT SCREEN */
  46.    od_set_attrib(window_colour[0]);
  47.    ny_clr_scr();                                          /* Clear the screen */
  48.  
  49. //   char numstr[100];
  50.  
  51.    if(rip==FALSE) {
  52.      od_set_cursor(bar_line,1);                   /* Draw window seperation bar */
  53.      od_set_attrib(bar_colour);
  54.      od_clr_line();
  55.      od_printf("  `black white`Top : `blue white`%s  `black white`Bottom : `blue white`%s  `red white`'/' = Command",
  56.          od_control.user_name,
  57.          od_control.sysop_name);
  58.    } else {
  59.      od_printf("`black black`");
  60.  
  61.      od_disp_str("\n\r!|*|1K|w0000270N12|Y00000100|1B00000202ZK02080F0F080700000807000000\n\r");
  62.      od_disp_str("!|1UDK4CHK4M0000<>Command<>^M/|1B000002027402080F0F080700000807000000\n\r");
  63.      od_disp_str("!|1U044CD44M0000|W0|c09|Y00000100|@0D4E");
  64.      od_printf("Top : %s  Bottom : %s|#|#|#\n\r  \b\b",od_control.user_name,od_control.sysop_name);
  65.      gotoxy(1,bar_line);                   /* Draw window seperation bar */
  66.      textbackground(WHITE);
  67.      clreol();
  68.      textcolor(BLACK);
  69.      cprintf("  Top : ");
  70.      textcolor(BLUE);
  71.      cprintf("%s  ",od_control.user_name);
  72.      textcolor(BLACK);
  73.      cprintf("Bottom : ");
  74.      textcolor(BLUE);
  75.      cprintf("%s  ",od_control.sysop_name);
  76.      textcolor(RED);
  77.      cprintf("'/' = Command");
  78.    }
  79.  
  80.    od_set_cursor(top_line[0],1);     /* Locate cursor where typing will begin */
  81.    od_set_attrib(window_colour[0]);            /* Set appropriate text colour */
  82.  
  83.                                 /* MAIN CHAT LOOP */
  84.    for(;;)                              /* (Repeats for each character typed) */
  85.       {
  86.       key=(char)od_get_key(TRUE);         /* Get next keystroke from keyboard */
  87.  
  88.                              /* CHECK FOR SYSOP ABORT */
  89.       if(key==27 && od_control.od_last_input==1)    /* If sysop pressed [ESC] */
  90.      {
  91.      od_set_attrib(0x07);                         /* Reset display colour */
  92.      ny_clr_scr();                                    /* Clear the screen */
  93.      od_control.key_chat=old_chat_key;    /* Re-enable internal chat mode */
  94.  
  95.      return;                                     /* Exit full-screen chat */
  96.      }
  97.  
  98.                               /* CHECK FOR NEW TYPIST */
  99.       if(od_control.od_last_input!=cursor_window) /* If new person typing now */
  100.      {                             /* Switch cursor to appropriate window */
  101.      cursor_window=od_control.od_last_input;        /* Set current typist */
  102.  
  103.                          /* Move cursor to new window */
  104.      od_set_cursor(cursor_line[cursor_window],cursor_col[cursor_window]);
  105.  
  106.      od_set_attrib(window_colour[cursor_window]);   /* Change text colour */
  107.      }
  108.  
  109.  
  110.       if(command[od_control.od_last_input]==TRUE)                  /* if user enabled the command mode */
  111.      {
  112.      if (key=='L' || key=='l') {
  113.         if (od_control.od_last_input==1) {
  114.           printf("\r");
  115.           printf("                                                           \r");
  116.           od_printf("`bright green`%s `dark green`laughs...",od_control.sysop_name);
  117.           chat_new_line();                                /* Move to next line */
  118.           command[1]=FALSE;
  119.         } else {
  120.           od_disp("\r",1,FALSE);
  121.           od_disp("                                                           \r",60,FALSE);
  122.           od_printf("`bright green`%s `dark green`laughs...",od_control.user_name);
  123.           chat_new_line();                                /* Move to next line */
  124.           command[0]=FALSE;
  125.         }
  126.         key=0;
  127.      }
  128.      else if (key=='S' || key=='s') {
  129.         if (od_control.od_last_input==1) {
  130.           printf("\r");
  131.           printf("                                                           \r");
  132.           od_printf("`bright green`%s `dark green`sighs...",od_control.sysop_name);
  133.           chat_new_line();                                /* Move to next line */
  134.           command[1]=FALSE;
  135.         } else {
  136.           od_disp("\r",1,FALSE);
  137.           od_disp("                                                           \r",60,FALSE);
  138.           od_printf("`bright green`%s `dark green`sighs...",od_control.user_name);
  139.           chat_new_line();                                /* Move to next line */
  140.           command[0]=FALSE;
  141.         }
  142.         key=0;
  143.      }
  144.      else if (key=='W' || key=='w') {
  145.         if (od_control.od_last_input==1) {
  146.           printf("\r");
  147.           printf("                                                           \r");
  148.           od_printf("`bright green`%s `dark green`winks at `bright green`%s`dark green`...",od_control.sysop_name,od_control.user_name);
  149.           chat_new_line();                                /* Move to next line */
  150.           command[1]=FALSE;
  151.         } else {
  152.           od_disp("\r",1,FALSE);
  153.           od_disp("                                                           \r",60,FALSE);
  154.           od_printf("`bright green`%s `dark green`winks at `bright green`%s`dark green`...",od_control.user_name,od_control.sysop_name);
  155.           chat_new_line();                                /* Move to next line */
  156.           command[0]=FALSE;
  157.         }
  158.         key=0;
  159.      }
  160.      else if (key=='C' || key=='c') {
  161.         if (od_control.od_last_input==1) {
  162.           printf("\r");
  163.           printf("                                                           \r");
  164.           od_printf("`bright green`%s `dark green`is crying...",od_control.sysop_name);
  165.           chat_new_line();                                /* Move to next line */
  166.           command[1]=FALSE;
  167.         } else {
  168.           od_disp("\r",1,FALSE);
  169.           od_disp("                                                           \r",60,FALSE);
  170.           od_printf("`bright green`%s `dark green`is crying...",od_control.user_name);
  171.           chat_new_line();                                /* Move to next line */
  172.           command[0]=FALSE;
  173.         }
  174.         key=0;
  175.      }
  176.      else {
  177.         if (od_control.od_last_input==1) {
  178.           cprintf("\r");
  179.           cprintf("                                                           \r");
  180.           command[1]=FALSE;
  181.         } else {
  182.           od_disp("\r",1,FALSE);
  183.           od_disp("                                                           \r",60,FALSE);
  184.           command[0]=FALSE;
  185.         }
  186.         key=0;
  187.      }
  188.      od_set_attrib(window_colour[cursor_window]);   /* Change text colour */
  189.       }
  190.  
  191.  
  192.       else if (key=='/')                  /* if user enabled the command mode */
  193.      {
  194.      if(cursor_col[cursor_window] == 1)       /* only if at left of screen */
  195.      {
  196.         if (od_control.od_last_input==1) {
  197.           textcolor(WHITE);
  198.           textbackground(BLACK);
  199.           cprintf("Do what: (L=Laugh, S=Sigh, W=Wink, C=Cry, Other=Continue) >");
  200.           command[1]=TRUE;
  201.         } else {
  202.           if(rip==FALSE)
  203.         od_disp("Do what: (L=Laugh, S=Sigh, W=Wink, C=Cry, Other=Continue) >",59,FALSE);
  204.           else
  205.         od_disp("\r!|10((*Command::L@Laugh,S@Sigh,W@Wink,C@Cry,^M@Continue))|#|#|#\n\r",69,FALSE);
  206.           command[0]=TRUE;
  207.         }
  208.         key=0;
  209.      }
  210.       }
  211.  
  212.       if(key==13 || key==10)            /* IF USER PRESSED [ENTER] / [RETURN] */
  213.      {
  214.      word_length[cursor_window]=0;       /* Enter constitutes end of word */
  215.  
  216.      chat_new_line();                                /* Move to next line */
  217.      }
  218.  
  219.       else if(key==8)                            /* IF USER PRESS [BACKSPACE] */
  220.      {
  221.      if(cursor_col[cursor_window] > 1)        /* If not at left of screen */
  222.         {
  223.         --cursor_col[cursor_window];     /* Move cursor back on character */
  224.         if(word_length[cursor_window] > 0) --word_length[cursor_window];
  225.         od_printf("\b \b");           /* Erase last character from screen */
  226.         }
  227.      }
  228.  
  229.  
  230.       else if(key==32)                             /* IF USER PRESSED [SPACE] */
  231.      {
  232.      word_length[cursor_window]=0;     /* [Space] constitutes end of word */
  233.  
  234.      if(cursor_col[cursor_window]==79)               /* If at end of line */
  235.         chat_new_line();                      /* Move cursor to next line */
  236.      else                                        /* If not at end of line */
  237.         {
  238.         ++cursor_col[cursor_window];         /* Increment cursor position */
  239.         od_putch(32);                                  /* Display a space */
  240.         }
  241.          }
  242.  
  243.  
  244.       else if(key>32)                  /* IF USER TYPED A PRINTABLE CHARACTER */
  245.      {                                  /* PERFORM WORD WRAP IF NECESSARY */
  246.      if(cursor_col[cursor_window]==79)     /* If cursor is at end of line */
  247.             {
  248.                         /* If there is a word to wrap */
  249.         if(word_length[cursor_window]>0 && word_length[cursor_window]<78)
  250.            {
  251.                       /* Move cursor to beginning of word */
  252.                od_set_cursor(cursor_line[cursor_window],
  253.               cursor_col[cursor_window]-word_length[cursor_window]);
  254.  
  255.            od_clr_line();                 /* Erase word from current line */
  256.  
  257.                chat_new_line();                   /* Move cursor to next line */
  258.  
  259.                                 /* Redisplay word */
  260.            od_disp(current_word[cursor_window],word_length[cursor_window],
  261.                                       TRUE);
  262.            cursor_col[cursor_window]+=word_length[cursor_window];
  263.            }
  264.  
  265.         else                             /* If there is no word to "wrap" */
  266.            {
  267.                chat_new_line();                   /* Move cursor to next line */
  268.                word_length[cursor_window]=0;              /* Start a new word */
  269.                }
  270.             }
  271.  
  272.                          /* ADD CHARACTER TO CURRENT WORD */
  273.                    /* If there is room for more character in word */
  274.      if(strlen(current_word[cursor_window])<79)      /* Add new character */
  275.         current_word[cursor_window][word_length[cursor_window]++]=key;
  276.  
  277.                          /* DISPLAY NEWLY TYPED CHARACTER */
  278.      ++cursor_col[cursor_window];
  279.      od_putch(key);
  280.      }
  281.       }
  282.    }
  283.  
  284.  
  285.  
  286.            /* FUNCTION USED BY FULL-SCREEN CHAT TO START A NEW INPUT LINE */
  287. void chat_new_line(void)
  288.    {                                      /* If cursor is at bottom of window */
  289.    if(cursor_line[cursor_window]==bottom_line[cursor_window])
  290.       {                                /* Scroll window up one line on screen */
  291.       od_scroll(1,top_line[cursor_window],79, bottom_line[cursor_window],
  292.         scroll_distance, 0);
  293.       cursor_line[cursor_window]-=(scroll_distance - 1);
  294.       }
  295.  
  296.    else                               /* If cursor is not at bottom of window */
  297.       {
  298.       ++cursor_line[cursor_window];              /* Move cursor down one line */
  299.       }
  300.  
  301.                                           /* Move cursor's position on screen */
  302.    od_set_cursor(cursor_line[cursor_window],cursor_col[cursor_window]=1);
  303.  
  304.    od_set_attrib(window_colour[cursor_window]);         /* Change text colour */
  305.    }
  306.